1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module sourceview.FileSaver;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.FileIF;
30 private import glib.ConstructionException;
31 private import glib.ErrorG;
32 private import glib.GException;
33 private import gobject.ObjectG;
34 private import sourceview.Buffer;
35 private import sourceview.Encoding;
36 private import sourceview.File;
37 private import sourceview.c.functions;
38 public  import sourceview.c.types;
39 
40 
41 /**
42  * Save a [class@Buffer] into a file.
43  * 
44  * A `GtkSourceFileSaver` object permits to save a [class@Buffer] into a
45  * [iface@Gio.File].
46  * 
47  * A file saver should be used only for one save operation, including errors
48  * handling. If an error occurs, you can reconfigure the saver and relaunch the
49  * operation with [method@FileSaver.save_async].
50  */
51 public class FileSaver : ObjectG
52 {
53 	/** the main Gtk struct */
54 	protected GtkSourceFileSaver* gtkSourceFileSaver;
55 
56 	/** Get the main Gtk struct */
57 	public GtkSourceFileSaver* getFileSaverStruct(bool transferOwnership = false)
58 	{
59 		if (transferOwnership)
60 			ownedRef = false;
61 		return gtkSourceFileSaver;
62 	}
63 
64 	/** the main Gtk struct as a void* */
65 	protected override void* getStruct()
66 	{
67 		return cast(void*)gtkSourceFileSaver;
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (GtkSourceFileSaver* gtkSourceFileSaver, bool ownedRef = false)
74 	{
75 		this.gtkSourceFileSaver = gtkSourceFileSaver;
76 		super(cast(GObject*)gtkSourceFileSaver, ownedRef);
77 	}
78 
79 
80 	/** */
81 	public static GType getType()
82 	{
83 		return gtk_source_file_saver_get_type();
84 	}
85 
86 	/**
87 	 * Creates a new #GtkSourceFileSaver object. The @buffer will be saved to the
88 	 * [class@File]'s location.
89 	 *
90 	 * This constructor is suitable for a simple "save" operation, when the @file
91 	 * already contains a non-%NULL [property@File:location].
92 	 *
93 	 * Params:
94 	 *     buffer = the #GtkSourceBuffer to save.
95 	 *     file = the #GtkSourceFile.
96 	 *
97 	 * Returns: a new #GtkSourceFileSaver object.
98 	 *
99 	 * Throws: ConstructionException GTK+ fails to create the object.
100 	 */
101 	public this(Buffer buffer, File file)
102 	{
103 		auto __p = gtk_source_file_saver_new((buffer is null) ? null : buffer.getBufferStruct(), (file is null) ? null : file.getFileStruct());
104 
105 		if(__p is null)
106 		{
107 			throw new ConstructionException("null returned by new");
108 		}
109 
110 		this(cast(GtkSourceFileSaver*) __p, true);
111 	}
112 
113 	/**
114 	 * Creates a new #GtkSourceFileSaver object with a target location.
115 	 *
116 	 * When the file saving is finished successfully, @target_location is set to the @file's
117 	 * [property@File:location] property. If an error occurs, the previous valid
118 	 * location is still available in [class@File].
119 	 *
120 	 * This constructor is suitable for a "save as" operation, or for saving a new
121 	 * buffer for the first time.
122 	 *
123 	 * Params:
124 	 *     buffer = the #GtkSourceBuffer to save.
125 	 *     file = the #GtkSourceFile.
126 	 *     targetLocation = the #GFile where to save the buffer to.
127 	 *
128 	 * Returns: a new #GtkSourceFileSaver object.
129 	 *
130 	 * Throws: ConstructionException GTK+ fails to create the object.
131 	 */
132 	public this(Buffer buffer, File file, FileIF targetLocation)
133 	{
134 		auto __p = gtk_source_file_saver_new_with_target((buffer is null) ? null : buffer.getBufferStruct(), (file is null) ? null : file.getFileStruct(), (targetLocation is null) ? null : targetLocation.getFileStruct());
135 
136 		if(__p is null)
137 		{
138 			throw new ConstructionException("null returned by new_with_target");
139 		}
140 
141 		this(cast(GtkSourceFileSaver*) __p, true);
142 	}
143 
144 	/**
145 	 * Returns: the #GtkSourceBuffer to save.
146 	 */
147 	public Buffer getBuffer()
148 	{
149 		auto __p = gtk_source_file_saver_get_buffer(gtkSourceFileSaver);
150 
151 		if(__p is null)
152 		{
153 			return null;
154 		}
155 
156 		return ObjectG.getDObject!(Buffer)(cast(GtkSourceBuffer*) __p);
157 	}
158 
159 	/**
160 	 * Returns: the compression type.
161 	 */
162 	public GtkSourceCompressionType getCompressionType()
163 	{
164 		return gtk_source_file_saver_get_compression_type(gtkSourceFileSaver);
165 	}
166 
167 	/**
168 	 * Returns: the encoding.
169 	 */
170 	public Encoding getEncoding()
171 	{
172 		auto __p = gtk_source_file_saver_get_encoding(gtkSourceFileSaver);
173 
174 		if(__p is null)
175 		{
176 			return null;
177 		}
178 
179 		return ObjectG.getDObject!(Encoding)(cast(GtkSourceEncoding*) __p);
180 	}
181 
182 	/**
183 	 * Returns: the #GtkSourceFile.
184 	 */
185 	public File getFile()
186 	{
187 		auto __p = gtk_source_file_saver_get_file(gtkSourceFileSaver);
188 
189 		if(__p is null)
190 		{
191 			return null;
192 		}
193 
194 		return ObjectG.getDObject!(File)(cast(GtkSourceFile*) __p);
195 	}
196 
197 	/**
198 	 * Returns: the flags.
199 	 */
200 	public GtkSourceFileSaverFlags getFlags()
201 	{
202 		return gtk_source_file_saver_get_flags(gtkSourceFileSaver);
203 	}
204 
205 	/**
206 	 * Returns: the #GFile where to save the buffer to.
207 	 */
208 	public FileIF getLocation()
209 	{
210 		auto __p = gtk_source_file_saver_get_location(gtkSourceFileSaver);
211 
212 		if(__p is null)
213 		{
214 			return null;
215 		}
216 
217 		return ObjectG.getDObject!(FileIF)(cast(GFile*) __p);
218 	}
219 
220 	/**
221 	 * Returns: the newline type.
222 	 */
223 	public GtkSourceNewlineType getNewlineType()
224 	{
225 		return gtk_source_file_saver_get_newline_type(gtkSourceFileSaver);
226 	}
227 
228 	/**
229 	 * Saves asynchronously the buffer into the file.
230 	 *
231 	 * See the [iface@Gio.AsyncResult] documentation to know how to use this function.
232 	 *
233 	 * Params:
234 	 *     ioPriority = the I/O priority of the request. E.g. %G_PRIORITY_LOW,
235 	 *         %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH.
236 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
237 	 *     progressCallback = function to call back with
238 	 *         progress information, or %NULL if progress information is not needed.
239 	 *     progressCallbackData = user data to pass to @progress_callback.
240 	 *     progressCallbackNotify = function to call on
241 	 *         @progress_callback_data when the @progress_callback is no longer needed, or
242 	 *         %NULL.
243 	 *     callback = a #GAsyncReadyCallback to call when the request is
244 	 *         satisfied.
245 	 *     userData = user data to pass to @callback.
246 	 */
247 	public void saveAsync(int ioPriority, Cancellable cancellable, GFileProgressCallback progressCallback, void* progressCallbackData, GDestroyNotify progressCallbackNotify, GAsyncReadyCallback callback, void* userData)
248 	{
249 		gtk_source_file_saver_save_async(gtkSourceFileSaver, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressCallbackData, progressCallbackNotify, callback, userData);
250 	}
251 
252 	/**
253 	 * Finishes a file saving started with [method@FileSaver.save_async].
254 	 *
255 	 * If the file has been saved successfully, the following [class@File]
256 	 * properties will be updated: the location, the encoding, the newline type and
257 	 * the compression type.
258 	 *
259 	 * Since the 3.20 version, [method@Gtk.TextBuffer.set_modified] is called with %FALSE
260 	 * if the file has been saved successfully.
261 	 *
262 	 * Params:
263 	 *     result = a #GAsyncResult.
264 	 *
265 	 * Returns: whether the file was saved successfully.
266 	 *
267 	 * Throws: GException on failure.
268 	 */
269 	public bool saveFinish(AsyncResultIF result)
270 	{
271 		GError* err = null;
272 
273 		auto __p = gtk_source_file_saver_save_finish(gtkSourceFileSaver, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
274 
275 		if (err !is null)
276 		{
277 			throw new GException( new ErrorG(err) );
278 		}
279 
280 		return __p;
281 	}
282 
283 	/**
284 	 * Sets the compression type. By default the compression type is taken from the
285 	 * #GtkSourceFile.
286 	 *
287 	 * Params:
288 	 *     compressionType = the new compression type.
289 	 */
290 	public void setCompressionType(GtkSourceCompressionType compressionType)
291 	{
292 		gtk_source_file_saver_set_compression_type(gtkSourceFileSaver, compressionType);
293 	}
294 
295 	/**
296 	 * Sets the encoding. If @encoding is %NULL, the UTF-8 encoding will be set.
297 	 *
298 	 * By default the encoding is taken from the #GtkSourceFile.
299 	 *
300 	 * Params:
301 	 *     encoding = the new encoding, or %NULL for UTF-8.
302 	 */
303 	public void setEncoding(Encoding encoding)
304 	{
305 		gtk_source_file_saver_set_encoding(gtkSourceFileSaver, (encoding is null) ? null : encoding.getEncodingStruct());
306 	}
307 
308 	/** */
309 	public void setFlags(GtkSourceFileSaverFlags flags)
310 	{
311 		gtk_source_file_saver_set_flags(gtkSourceFileSaver, flags);
312 	}
313 
314 	/**
315 	 * Sets the newline type. By default the newline type is taken from the
316 	 * #GtkSourceFile.
317 	 *
318 	 * Params:
319 	 *     newlineType = the new newline type.
320 	 */
321 	public void setNewlineType(GtkSourceNewlineType newlineType)
322 	{
323 		gtk_source_file_saver_set_newline_type(gtkSourceFileSaver, newlineType);
324 	}
325 }